//accepted 
#include <cstdio>
int n, k, x, r;
int main(){
	freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);
	while(scanf("%d%d", &n, &k)==2){
		x=n;
		r=n%k;
		while(n/=k){
			x+=n;
			n+=r;
			r=n%k;
		}
		printf("%d\n", x);
	}
	return 0;
}
